package net.ikenway.springboot.demo.oauth.Controller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * @author MasterKenway <zk@ikenway.net>
 * @Description
 * @date Created Date 12/4/2020
 */
@RestController
public class AuthController {
    @RequestMapping(value = "/user", method = RequestMethod.GET)
    public Map<String, Object> User() {
        SecurityContext context = SecurityContextHolder.getContext();
        Authentication authentication = context.getAuthentication();
        String username = authentication.getName();
        Object principal = authentication.getPrincipal();
        Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
        Map<String, Object> map = new HashMap<>();
        map.put("username", username);
//        map.put("principal", principal);
        return map;
    }

//    @RequestMapping("/login")
//    public String Login() {
//        return ;
//    }

    @RequestMapping(value = "/test", method = RequestMethod.GET)
    public String Test() {
        return "Auth Success";
    }

}
